﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Xml.Linq;

namespace BulldogCMS.Data.Tests
{
    [TestClass]
    public class XMLTemplatesProviderTest
    {
        private BulldogCMS.Data.Templates.ITemplatesProvider CreateXMLProvider()
        {
            XDocument templatesXDoc = XDocument.Load(TestingData.ReflectionHelper.GetResourceStream("BulldogCMS.Data.Tests.TestingData.VolksbankWeb.xml"));
            BulldogCMS.Data.Templates.XMLTemplatesProvider xmlTemplatesProvider = new Templates.XMLTemplatesProvider(templatesXDoc);
            return xmlTemplatesProvider;
        }

        [TestMethod]
        public void LoadTemplatesFromXML()
        {
            Assert.AreEqual(16, this.CreateXMLProvider().Templates.Count(), "Number of templates is not equal");
        }

        [TestMethod]
        public void GetTemplate()
        {
            var template = this.CreateXMLProvider().GetTemplate("ContentPage");
            Assert.IsNotNull(template, "Template ContentPage not found");
            Assert.AreEqual(2, template.FieldDefinitions.Count());
            Assert.AreEqual(true, template.AllowAllTemplates, "ContentPage should allow all templates");
        }

        [TestMethod]
        public void NonExistingTemplateIsNull()
        {
            var template = this.CreateXMLProvider().GetTemplate("ABCD");
            Assert.IsNull(template, "Non existing template should be null");
        }

    }
}
